package com.iter.devbox.pattern.flyweight;

import java.util.ArrayList;
import java.util.List;

/**客户端调用*/
public class Client {

	public static void main(String[] args) {
		FlyweightFactory factory = new FlyweightFactory();
        Flyweight fly = factory.factory(new String("a"));
        fly.operation("First Call");
        System.out.println("a状态的享元对象：" + fly);
        
        fly = factory.factory(new String("b"));
        fly.operation("Second Call");
        System.out.println("b状态的享元对象：" + fly);
        
        fly = factory.factory(new String("a"));
        fly.operation("Third Call");
        System.out.println("a状态的享元对象：" + fly);
		
		
		/*List<String> compositeState = new ArrayList<String>();
        compositeState.add("a");
        compositeState.add("b");
        compositeState.add("c");
        compositeState.add("a");
        compositeState.add("b");
        
        CompositeFlyweightFactory flyFactory = new CompositeFlyweightFactory();
        Flyweight compositeFly1 = flyFactory.factory(compositeState);
        System.out.println("1：" +compositeFly1);  
        Flyweight compositeFly2 = flyFactory.factory(compositeState);
        System.out.println("2：" +compositeFly2);  
        System.out.println("复合享元模式是否可以共享对象：" + (compositeFly1 == compositeFly2));
        
        String state = "a";
        Flyweight fly1 = flyFactory.factory(state);
        System.out.println("3：" +fly1);  
        Flyweight fly2 = flyFactory.factory(state);
        System.out.println("4：" +fly2);  
        System.out.println("单纯享元模式是否可以共享对象：" + (fly1 == fly2));*/
	}
}

